package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.DateUtil;
import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;

//日报
@Getter@Setter
public class NewsPage extends BaseDomain{

    //标题
    private String title;
    //副标题
    private String subTitle;
    //创建时间
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8")
    private Date createTime;
    //发布时间
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8")
    private Date releaseTime;
    //状态
    private Boolean status;
    //背景
    private String coverUrl;
    //日报内容
    private NewsContent newsContent;


    public String getJson(){
        HashMap<String, Object> map = new HashMap<>();
        map.put("id",id);
        map.put("title",title);
        map.put("subTitle",subTitle);
        map.put("coverUrl",coverUrl);
        map.put("status",status);
        map.put("releaseTime", DateUtil.formatDate(releaseTime));
        if(newsContent!=null){
            map.put("newsContentId",newsContent.id);
        }
        return JSONUtil.toJSONString(map);
    }

}